package com.zzty.txj1.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zzty.txj1.entity.Message;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 2YSP on 2017/7/12.
 */
public class ResponseMessageUtil {
    public static final String URL = "http://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN";
    public static String responseMessage(String openId,String eventName) throws Exception{
        //获取token
        String token = WeiChatUtil.getAccessToken();
        String url = URL.replace("ACCESS_TOKEN", token);

        Message massMessage = new Message();
        List<String> list = new ArrayList<String>();
        list.add(openId);
        list.add(openId);
        massMessage.setTouser(list);
        massMessage.setMsgtype("text");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("content", eventName+"已打卡！");
        massMessage.setText(map);

        Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
        String str = gson.toJson(massMessage);
        System.out.println("str:"+str);

        String jso = HttpUtil.httpPostWithJSON(url, str);
        System.out.println(jso.toString());
        return jso;
    }
}